package br.ufpe.cin.dsoa.manager;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.osgi.service.monitor.Monitorable;
import org.osgi.service.monitor.StatusVariable;

import br.ufpe.cin.dsoa.manager.metadata.Slo;

public class MetricService implements Monitorable {
	
	Map<String, Float> metricMap = new ConcurrentHashMap<String, Float>();

	public MetricService(List<Slo> slos) {
		for(Slo s : slos){
			String key = "";
			
			if(s.getOperation() != null) {
				key += s.getOperation();
			}
			
			key += s.getMetric();
			metricMap.put(key, (float) s.getThreshold());
		}
	}

	@Override
	public String[] getStatusVariableNames() {
		return metricMap.keySet().toArray(new String[0]);
	}

	@Override
	public StatusVariable getStatusVariable(String id)
			throws IllegalArgumentException {
		return new StatusVariable(id, StatusVariable.CM_GAUGE, metricMap.get(id));
	}

	@Override
	public boolean notifiesOnChange(String id)
			throws IllegalArgumentException {
		return false;
	}

	@Override
	public boolean resetStatusVariable(String id)
			throws IllegalArgumentException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public String getDescription(String id)
			throws IllegalArgumentException {
		String desc = "Foo.bar";
		return desc;
	}
	
}